Data Internal Export
The dReveal grid component provides methods to export its data to a file or stream in PDF, RawData and XLSX format. These methods are available on the server side.
Server Side Export
The methods provided by the grid component on the server side are detailed below:
Name | Return | Format |
---|---|---|
ExportTo | ActionResult | |
ExportTo | ActionResult | RawData |
ExportTo | ActionResult | XLSX |
These methods are located in the
Utils
class from the namespaceInfoArch.Web.Mvc.Helpers
.
It is important to mention that exists some properties in the GridSettings
object located into the GridViewModel
class, for customizing the Excel exportation. These properties are detailed below:
Property | Description |
---|---|
GridSettings.CustomFileName | Excel file name |
GridSettings.CustomTitle | The title of the report in the Excel file |
Controller
The following code demonstrates how to implement the methods in a controller class:
[HttpPost]
public FileStreamResult GridReportPdf([ModelBinder(typeof(DRevealDataStructureBinder))] DRevealDataStructure gridState)
{
// Create GridViewModel
GridViewModel viewModel = GetGridViewModel();
viewModel.SetState(gridboardState);
viewModel.LoadInitialConfiguration();
// Set config in GridSettings
viewModel.GridSettings.CustomFileName = "MyPdfGrid";
viewModel.GridSettings.CustomTitle = "Title Grid";
//Export Excel
return Utils.ExportTo(gridState.ExportType, gridViewModel, Response);
}
[HttpPost]
public FileStreamResult GridReportExcel([ModelBinder(typeof(DRevealDataStructureBinder))] DRevealDataStructure gridState)
{
// Create GridViewModel
GridViewModel viewModel = GetGridViewModel();
viewModel.SetState(gridboardState);
viewModel.LoadInitialConfiguration();
// Set config in GridSettings
viewModel.GridSettings.CustomFileName = "MyExcelGrid";
viewModel.GridSettings.CustomTitle = "Title Grid";
// If value is FALSE, this line is optional
viewModel.SetXLExportModeOnlyData(false);
// Export Excel
return Utils.ExportTo(gridState.ExportType, gridViewModel, Response);
}
[HttpPost]
public FileStreamResult GridReportRawData([ModelBinder(typeof(DRevealDataStructureBinder))] DRevealDataStructure gridState)
{
// Create GridViewModel
GridViewModel viewModel = GetGridViewModel();
viewModel.SetState(gridboardState);
viewModel.LoadInitialConfiguration();
viewModel.SetXLExportModeOnlyData(true);
// Set config in GridSettings
viewModel.GridSettings.CustomFileName = "MyRawDataGrid";
viewModel.GridSettings.CustomTitle = "Title Grid";
// Export Excel
return Utils.ExportTo(gridState.ExportType, gridViewModel, Response);
}
private GridViewModel GetGridViewModel()
{
return new GridViewModel(
memoryStream: fileStream,
connectionString: "Data Source=MyServer; Initial Catalog=myDatabase; User ID=myUser; Password=myPassword",
gridId: "grid_id",
htmlFormId: "main_form",
rowsPerPage: 15,
enableColumnFinderFeature: true,
isGridPagerSimpleMode: true,
fullGridControllerActionPath: HttpContext.Request.Url.AbsolutePath,
gridActionName: string.Empty,
drillThroughControllerAction: string.Empty,
saveGridControllerAction: string.Empty,
exportToExcelGridControllerAction: string.Empty
);
}
Client Side Export
The following code demonstrates how to call to the server side methods:
<form id="main_form" method="post">
<div>
<button
type="submit"
formaction="@Url.Action("GridExportPdf")"
formmethod="post"
name="dr_gridExport"
value="pdf">Download PDF</button>
<button
type="submit"
formaction="@Url.Action("GridExportExcel")"
formmethod="post"
name="dr_gridExport"
value="xlsxXL">Download EXCEL</button>
<button
type="submit"
formaction="@Url.Action("GridExportRawData")"
formmethod="post"
name="dr_gridExport"
value="xlsxXL">Download RAW DATA</button>
</div>
</form>
Export requests require sending an input field with the name
dr_gridExport
. The supported values arexlsxXL
for downloading files of type EXCEL and RAW DATA.The decision of whether to download EXCEL or RAW DATA is made by the GridViewModel object, using the
SetXLExportModeOnlyData(bool enable)
method. The value TRUE indicates that RAW DATA will be downloaded and the value FALSE indicates that EXCEL will be downloaded.